package com.yonglian.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yonglian.common.annotation.Log;
import com.yonglian.common.enums.BusinessType;
import com.yonglian.system.domain.CmsProjectType;
import com.yonglian.system.service.ICmsProjectTypeService;
import com.yonglian.common.core.controller.BaseController;
import com.yonglian.common.core.domain.AjaxResult;
import com.yonglian.common.utils.poi.ExcelUtil;
import com.yonglian.common.core.page.TableDataInfo;

/**
 * 项目类型Controller
 * 
 * @author gyok
 * @date 2024-05-28
 */
@Controller
@RequestMapping("/system/projectType")
public class CmsProjectTypeController extends BaseController
{
    private String prefix = "system/projectType";

    @Autowired
    private ICmsProjectTypeService cmsProjectTypeService;

    @RequiresPermissions("system:projectType:view")
    @GetMapping()
    public String projectType()
    {
        return prefix + "/projectType";
    }

    /**
     * 查询项目类型列表
     */
    @RequiresPermissions("system:projectType:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsProjectType cmsProjectType)
    {
        startPage();
        List<CmsProjectType> list = cmsProjectTypeService.selectCmsProjectTypeList(cmsProjectType);
        return getDataTable(list);
    }

    /**
     * 导出项目类型列表
     */
    @RequiresPermissions("system:projectType:export")
    @Log(title = "项目类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsProjectType cmsProjectType)
    {
        List<CmsProjectType> list = cmsProjectTypeService.selectCmsProjectTypeList(cmsProjectType);
        ExcelUtil<CmsProjectType> util = new ExcelUtil<CmsProjectType>(CmsProjectType.class);
        return util.exportExcel(list, "项目类型数据");
    }

    /**
     * 新增项目类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存项目类型
     */
    @RequiresPermissions("system:projectType:add")
    @Log(title = "项目类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsProjectType cmsProjectType)
    {
        return toAjax(cmsProjectTypeService.insertCmsProjectType(cmsProjectType));
    }

    /**
     * 修改项目类型
     */
    @RequiresPermissions("system:projectType:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CmsProjectType cmsProjectType = cmsProjectTypeService.selectCmsProjectTypeById(id);
        mmap.put("cmsProjectType", cmsProjectType);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目类型
     */
    @RequiresPermissions("system:projectType:edit")
    @Log(title = "项目类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsProjectType cmsProjectType)
    {
        return toAjax(cmsProjectTypeService.updateCmsProjectType(cmsProjectType));
    }

    /**
     * 删除项目类型
     */
    @RequiresPermissions("system:projectType:remove")
    @Log(title = "项目类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsProjectTypeService.deleteCmsProjectTypeByIds(ids));
    }
}
